package com.gsn.chooseRoom;

import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.gsn.dataCommon.ConfigModel;
import com.gsn.dataCommon.TableModel;
import com.gsn.poker.asset.PortalTexture;

public class ListChooseRoom extends Group {
	ButtonRoom buttonRoom[];

	public ListChooseRoom(float width) {
		this.width = width;

	}

	// public void update() {
	// clear();
	//
	// int i;
	// buttonRoom = new ButtonRoom[ConfigModel.tableModelList.size()];
	// int size = buttonRoom.length;
	// for (i = size - 1; i >= 0; i--) {
	// buttonRoom[i] = new ButtonRoom(i);
	// addActor(buttonRoom[i]);
	// if (i != size - 1)
	// buttonRoom[i].y = (size - i - 1) * buttonRoom[i].height * 1.1f;
	// else
	// buttonRoom[i].y = (size - i - 1) * buttonRoom[i].height;
	//
	// }
	//
	// if (buttonRoom.length == 0) {
	// height = 0;
	// return;
	// }
	// height = buttonRoom.length * buttonRoom[0].height + (buttonRoom.length -
	// 1) * buttonRoom[0].height * 0.1f;
	// }

	public void update() {
		clear();

		int i;
		buttonRoom = new ButtonRoom[ConfigModel.tableModelList.size()];
		Image image = new Image(PortalTexture.inst().chooseRoomButton);
		PortalTexture.inst().scaleActor(image);
		int size = buttonRoom.length;
		for (i = size - 1; i >= 0; i--) {

			float y;
			if (i != size - 1)
				y = (size - i - 1) * image.height * 1.1f;
			else
				y = (size - i - 1) * image.height;
			buttonRoom[i] = new ButtonRoom(i, y);
			buttonRoom[i].addActor(this);
			// addActor(buttonRoom[i]);

		}
		
		if (buttonRoom.length == 0) {
			height = 0;
			return;
		}
		height = buttonRoom.length * buttonRoom[0].height + (buttonRoom.length - 1) * buttonRoom[0].height * 0.1f;
		System.out.println("height    " + height  );
	}

	public void updateRoomNum() {
		// TODO Auto-generated method stub
		int i;
		for (i = 0; i < buttonRoom.length; i++) {
			TableModel table = ConfigModel.tableModelList.get(i);
			buttonRoom[i].setInfo(table.bet, table.personCount, table.tableName, table.type, table.index);
		}
	}

}
